/**
 * Created with IntelliJ IDEA.
 * User: Gauss
 * Date: 02.11.13
 * Time: 11:55
 * To change this template use File | Settings | File Templates.
 */
public class ParenthesesTester {

    public Result test(String testingString) {
        if (testingString.isEmpty()) {
          return Result.FAILED;
        }
        int balance = 0;
        for(Character symbol: testingString.toCharArray()) {
            if (symbol.compareTo('(')==0)
              balance++;
            else if (symbol.compareTo(')')==0)
              balance--;
            if (balance<0)
              return Result.FAILED_CLOSING;
        }
        if (balance!=0)
          return Result.FAILED_OPENING;
        return Result.OK;
    }

    //public String showResult() {}
  enum Result {
      OK("String correct"),
      FAILED_CLOSING("Test failed. Found an unexpected closing bracket"),
      FAILED_OPENING("Test failed. Found an unexpected opening bracket"),
      FAILED("Unexpected");


      Result(final String message) {
        this.message = message;
      }

      String getMessage() {
        return message;
      }

      private String message;
    }

}
